package pl.register.android.database.crud;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import pl.register.android.database.tables.StudentInYearDBTable;
import pl.register.android.student.Student;
import pl.register.android.year.Year;

/**
 * @author Mateusz Strzelecki
 * @since 2013-04-27
 */
public class StudentInYearCRUD {

    private SQLiteDatabase database;

    public StudentInYearCRUD(SQLiteDatabase database) {
        this.database = database;
    }

    public void insert(Student student, Year year) {
        ContentValues insertValues = new ContentValues();
        insertValues.put(StudentInYearDBTable.FK_YEAR_ID, year.getId());
        insertValues.put(StudentInYearDBTable.FK_STUDENT_ID, student.getId());
        long idRow = database.insert(StudentInYearDBTable.TABLE_NAME, null, insertValues);
    }

    public void delete(Student student, Year year) {
        String where = StudentInYearDBTable.FK_STUDENT_ID + " = " + student.getId()
                + " AND " +
                StudentInYearDBTable.FK_YEAR_ID + " = " + year.getId();
        int res = database.delete(StudentInYearDBTable.TABLE_NAME, where, null);
    }
}
